﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using GoogleMaps;

namespace libGoogleMapESB.Forms
{
    public partial class frmMapControls : Telerik.WinControls.UI.RadForm
    {
        private GoogleMapsNet googleMapsNet;
        private frmMap MAP;
        private double dblLongitude = 0;
        private double dblLatitude = 0;
        private string strOrigin = string.Empty;
        private string strDestination = string.Empty;

        public frmMapControls()
        {
            InitializeComponent();
        }

        public void setMap(ref frmMap Mp)
        {
            MAP = Mp;
        }

        private void frmMapControls_Load(object sender, EventArgs e)
        {
            googleMapsNet = new GoogleMapsNet();
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            dgvNearest.DataSource = (DataTable)googleMapsNet.AddressToLongitudeLatitude(txtDestination.Text.Trim());
            DataTable table = googleMapsNet.CalculateDistance(txtOrigin.Text.Trim(), txtDestination.Text.Trim());
            dgvDistance.DataSource = table;
        }


        private void radButton1_Click_1(object sender, EventArgs e)
        {
          //  googleMapsNet.ShowMap(mapType, dblLongitude, dblLatitude, intZoom);
          //  DataTable table = googleMapsNet.AddRoute(txtOrigin.Text.Trim(), txtDestination.Text.Trim());
            DialogResult = DialogResult.OK;
          //  dataGridViewDetails.DataSource = table;
        }

        public double get_Longitude
        {
            get
            {
                return dblLongitude; 
            }
        }

        public double get_Latitude
        {
            get
            {
                return dblLatitude;
            }
        }

        public string getOriginName
        {
            get
            {
                return txtOrigin.Text.Trim(); 
            }
        }

        public string getDestinationName
        {
            get
            {
              return txtDestination.Text.Trim();
            }
        }

        private void dgvNearest_CellClick(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
        {
            if (txtOrigin.Text.Trim() != string.Empty && txtDestination.Text.Trim() != string.Empty)
            {
                txtDestination.Text = dgvNearest.CurrentRow.Cells[0].Value.ToString().Trim();
                dblLongitude = Convert.ToDouble(dgvNearest.CurrentRow.Cells[1].Value);
                dblLatitude = Convert.ToDouble(dgvNearest.CurrentRow.Cells[2].Value);
            }
        }

        private void radButton2_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void radButton3_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }
    }
}
